/**
 * 项目名称: springcloudtest
 * 类名称: StudentService.java
 * 包名称: com.zw.trans.tx
 * <p>
 * 修改履历:
 * 日期       2019-11-11
 * 修正者     Thomas
 * 主要内容   初版做成
 * <p>
 * Copyright (c) 2016-2019
 */
package com.zw.trans.tx;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 * @Author Thomas 2019-11-11 15:45
 * The world of programs is a wonderful world
 */
@Service
public class StudentService {

    @Autowired
    private StudentDao studentDao;

    /**
     * PROPAGATION_NOT_SUPPORTED	以非事务方式执行操作，如果当前存在事务，就把当前事务挂起。
     * 就是，这个方法不参加事务管理，出现异常，该提交的就提交
     */
    @Transactional(propagation = Propagation.NOT_SUPPORTED)
    public void insert() {
        studentDao.insert();
        throw new RuntimeException();
    }

    @Transactional()
    public void insert1() {
        studentDao.insert();
        throw new RuntimeException();
    }

    @Transactional(propagation = Propagation.MANDATORY)
    public void insert2() {
        studentDao.insert();
        throw new RuntimeException();
    }

    @Transactional(propagation = Propagation.REQUIRES_NEW)
    public void insert3() {
        studentDao.insert();
        throw new RuntimeException();
    }

    @Transactional(propagation = Propagation.NESTED)
    public void insert4() {
        studentDao.insert();
        throw new RuntimeException();
    }

    @Transactional(propagation = Propagation.NOT_SUPPORTED)
    public void insert5() {
        studentDao.insert();
        throw new RuntimeException();
    }

    @Transactional(propagation = Propagation.NEVER)
    public void insert6() {
        studentDao.insert();
        throw new RuntimeException();
    }

    @Transactional(propagation = Propagation.NESTED)
    public void insert7() {
        studentDao.insert();
        throw new RuntimeException();
    }
}
